package com.whsr.readservice.dao;

import com.whsr.readservice.dto.JobBatchRequest;
import com.whsr.readservice.vo.DownBookMaintain;
import com.whsr.readservice.vo.JobBatch;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface JobBatchMapper {

    @Insert("<script>" +
            "insert into job_batch " +
            "<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">" +
            " job_type," +
            " create_time," +
            " update_time," +
            "<if test=\"completeArtNum != null\">" +
            " complete_art_num," +
            "</if>" +
            "<if test=\"failArtNum != null\">" +
            " fail_art_num," +
            "</if>" +
            "<if test=\"completeChpNum != null\">" +
            " complete_chp_num," +
            "</if>" +
            "<if test=\"failChpNum != null\">" +
            " fail_chp_num," +
            "</if>" +
            "<if test=\"completeChpArtNum != null\">" +
            " complete_chp_art_num," +
            "</if>" +
            "<if test=\"failChpArtNum != null\">" +
            " fail_chp_art_num," +
            "</if>" +
            "<if test=\"completeConNum != null\">" +
            " complete_con_num," +
            "</if>" +
            "<if test=\"failConNum != null\">" +
            " fail_con_num," +
            "</if>" +
            "<if test=\"completeConArtNum != null\">" +
            " complete_con_art_num," +
            "</if>" +
            "<if test=\"failConArtNum != null\">" +
            " fail_con_art_num," +
            "</if>" +
            "</trim>" +
            "<trim prefix=\"values (\" suffix=\")\" suffixOverrides=\",\">" +
            " #{jobType,jdbcType=INTEGER}" +
            "  #{createTime,jdbcType=TIMESTAMP}," +
            "  now()," +
            "<if test=\"completeArtNum != null\">" +
            "  #{completeArtNum,jdbcType=INTEGER}," +
            "</if>" +
            "<if test=\"failArtNum != null\">" +
            "  #{failArtNum,jdbcType=INTEGER}," +
            "</if>" +
            "<if test=\"completeChpNum != null\">" +
            "  #{completeChpNum,jdbcType=INTEGER}," +
            "</if>" +
            "<if test=\"failChpNum != null\">" +
            "  #{failChpNum,jdbcType=INTEGER}," +
            "</if>" +
            "<if test=\"completeChpArtNum != null\">" +
            "  #{completeChpArtNum,jdbcType=INTEGER}," +
            "</if>" +
            "<if test=\"failChpArtNum != null\">" +
            "  #{failChpArtNum,jdbcType=INTEGER}," +
            "</if>" +
            "<if test=\"completeConNum != null\">" +
            "  #{completeConNum,jdbcType=INTEGER}," +
            "</if>" +
            "<if test=\"failConNum != null\">" +
            "  #{failConNum,jdbcType=INTEGER}," +
            "</if>" +
            "<if test=\"completeConArtNum != null\">" +
            "  #{completeConArtNum,jdbcType=INTEGER}," +
            "</if>" +
            "<if test=\"failConArtNum != null\">" +
            "  #{failConArtNum,jdbcType=INTEGER}," +
            "</if>" +
            "</trim>" +
            "</script>")
    int insertJobBatch(JobBatch jobBatch);

    @Select("<script>" +
            "select " +
            " id id, " +
            " complete_art_num completeArtNum, " +
            " fail_art_num failArtNum, " +
            " complete_chp_num completeChpNum, " +
            " fail_chp_num failChpNum, " +
            " complete_chp_art_num completeChpArtNum, " +
            " fail_chp_art_num failChpArtNum, " +
            " complete_con_num completeConNum, " +
            " fail_con_num failConNum, " +
            " complete_con_art_num completeConArtNum, " +
            " fail_con_art_num failConArtNum, " +
            " job_type jobType, " +
            " create_time createTime, " +
            " update_time updateTime " +
            "FROM job_batch " +
            "WHERE 1=1 " +
            "<when test=\"jobType != null and jobType != ''\">" +
            " and job_type = #{jobType,jdbcType=INTEGER} " +
            "</when>" +
            "<when test=\"runDate != null and createTime != ''\">" +
            " and date(create_time) = #{runDate,jdbcType=TIMESTAMP} " +
            "</when>" +
            "order by create_time desc" +
            "</script>")
    List<JobBatchRequest> selectJobList(JobBatchRequest jobBatchRequest);
}
